
/*
 * HealthFormFrame.java
 *
 * Created on Jan 10, 2014, 11:35:13 PM
 */
package ca.cserkesz.healthform;

import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 *
 * @author George Laza <laza.gyuri@cserkesz.ca>
 */
public class HealthFormFrame extends javax.swing.JFrame {

    /** Creates new form HealthFormFrame */
    public HealthFormFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        m_openButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        m_scoutList = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        m_campName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        m_saveButton = new javax.swing.JButton();
        selectAll = new javax.swing.JButton();
        selectNone = new javax.swing.JButton();
        m_parsingBar = new javax.swing.JProgressBar();
        m_savingBar = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cserkész Egészségügyi Ürlap Töltő");

        jLabel1.setText("1) Excel táblázat kinyitása:");

        m_openButton.setText("Nyitás...");

        jScrollPane1.setViewportView(m_scoutList);

        jLabel2.setText("2) Tábor neve:");

        jLabel3.setText("3)  Tábor résztvevők:");

        jLabel4.setText("4) Egészségügyi ürlapokat töltése:");

        m_saveButton.setText("Mentés...");

        selectAll.setText("Mindenki");
        selectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectAllActionPerformed(evt);
            }
        });

        selectNone.setText("Senki");
        selectNone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectNoneActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(m_parsingBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(jLabel1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 62, Short.MAX_VALUE)
                                .add(m_openButton))
                            .add(layout.createSequentialGroup()
                                .add(jLabel2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(m_campName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel3)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(selectAll)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(selectNone))
                            .add(layout.createSequentialGroup()
                                .add(jLabel4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(m_saveButton)))
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(m_savingBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                        .add(22, 22, 22))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(m_openButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(m_parsingBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(m_campName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(selectAll)
                    .add(selectNone))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(m_saveButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(m_savingBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void selectNoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectNoneActionPerformed
    m_scoutList.clearSelection();
}//GEN-LAST:event_selectNoneActionPerformed

private void selectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllActionPerformed
    int end = m_scoutList.getModel().getSize() - 1;
    if (end >= 0) {
      m_scoutList.setSelectionInterval(0, end);
    }
}//GEN-LAST:event_selectAllActionPerformed

public void setSavingProgress(int percentage) {
    m_savingBar.setValue(percentage);
}

public void setParsingProgress(int percentage) {
    if (percentage == -1) {
        // Not working...
        m_parsingBar.setIndeterminate(true);
    } else {
        m_parsingBar.setValue(percentage);
    }
}

public String getCampName() {
    return m_campName.getText();
}

public void setScoutList(ArrayList<Scout> m_scoutList2) {
    m_scoutList.setListData(m_scoutList2.toArray());
}


ArrayList<Scout> getSelectedScouts() {
    ArrayList<Scout> list = new ArrayList<Scout>();
    int [] indices = m_scoutList.getSelectedIndices();
    
    for (int i : indices) {
        list.add((Scout)m_scoutList.getModel().getElementAt(i));
    }
    return list;
}

public void addOpenActionListener(ActionListener listener) {
    m_openButton.addActionListener(listener);
}

public void addSaveActionListener(ActionListener listener) {
    m_saveButton.addActionListener(listener);
}


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HealthFormFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HealthFormFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HealthFormFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HealthFormFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new HealthFormFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField m_campName;
    private javax.swing.JButton m_openButton;
    private javax.swing.JProgressBar m_parsingBar;
    private javax.swing.JButton m_saveButton;
    private javax.swing.JProgressBar m_savingBar;
    private javax.swing.JList m_scoutList;
    private javax.swing.JButton selectAll;
    private javax.swing.JButton selectNone;
    // End of variables declaration//GEN-END:variables



}
